package cn.school.course.vo;

import cn.school.course.entity.Course;
import cn.school.course.entity.CourseSessions;
import lombok.Data;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 课表行(节次)
 *
 * @className: CourseTableRow
 * @author: fangjin.tao
 * @date: 2023/2/1
 **/
@Data
public class CourseTableRow {
	/**
	 * 节次ID
	 */
	private String coseId;
	/**
	 * 节次时间
	 */
	private String time;
	/**
	 * 每周的课程
	 */
	Map<String, List<CourseRspVo>> claTimeWeekDayMap = new HashMap<>();
	
	public CourseTableRow(CourseSessions courseSessions, List<Course> courseList) {
		String coseCode = courseSessions.getCoseCode();
		String time = courseSessions.getCoseBeginTime().substring(0, 5) + " ~ " + courseSessions.getCoseEndTime().substring(0,5);
		this.coseId = courseSessions.getId().toString();
		this.time = time;
		
		Map<Integer, List<Course>> tempClaTimeWeekDayMap = null;
		if (courseList != null && courseList.size() != 0) {
			tempClaTimeWeekDayMap = courseList.stream().collect(Collectors.groupingBy(Course::getCoplWeekDayNo));
		}
		
		CourseRspVo tempCourseRspVo = null;
		for (int i = 1, size = 7; i <= 7; i++) {
			if (tempClaTimeWeekDayMap != null && tempClaTimeWeekDayMap.containsKey(i)) {
				List<Course> tempCourseList = tempClaTimeWeekDayMap.get(i);
				List<CourseRspVo> courseRspVoList = new ArrayList<>();
				for (Course course : tempCourseList) {
					tempCourseRspVo = new CourseRspVo();
					course.transfer(tempCourseRspVo);
					courseRspVoList.add(tempCourseRspVo);
				}
				claTimeWeekDayMap.put(i + "", courseRspVoList);
			} else {
				claTimeWeekDayMap.put(i + "", new ArrayList<>());
			}
		}
	}
	
}
